package com.ruoyi.device.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.HatDeviceLog;
import com.ruoyi.device.domain.HatDeviceOrderLogs;
import com.ruoyi.device.domain.req.Instructions.SendInstructionsReq;
import com.ruoyi.device.domain.req.orderlogs.OrderLogsReq;
import com.ruoyi.device.service.HatDeviceOrderLogsService;
import com.ruoyi.device.mapper.HatDeviceOrderLogsMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 11452
* @description 针对表【hat_device_order_logs(帽子指令发送和回复记录表)】的数据库操作Service实现
* @createDate 2023-11-28 17:24:48
*/
@Service
public class HatDeviceOrderLogsServiceImpl extends ServiceImpl<HatDeviceOrderLogsMapper, HatDeviceOrderLogs>
    implements HatDeviceOrderLogsService{

    @Override
    public List<HatDeviceOrderLogs> search(OrderLogsReq req) {
        LambdaQueryWrapper<HatDeviceOrderLogs> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(HatDeviceOrderLogs::getDeviceId,req.getDeviceId());
        queryWrapper.orderByDesc(HatDeviceOrderLogs::getCreateTime);
        return this.list(queryWrapper);
    }

    @Override
    public boolean sendInstructions(SendInstructionsReq sendInstructionsReq) {
        HatDeviceOrderLogs hatDeviceOrderLogs = new HatDeviceOrderLogs();
        hatDeviceOrderLogs.setDeviceId(sendInstructionsReq.getDeviceId());
        hatDeviceOrderLogs.setPublishInstructid(sendInstructionsReq.getInstructId());
        hatDeviceOrderLogs.setPublishOrder(JSON.toJSONString(sendInstructionsReq));
        return super.save(hatDeviceOrderLogs);
    }
}




